/******************************************************
 Project:				PCSync
 Author:				Jean-Philippe
 File name:				Controler.java
 Date created:			2012-10-01
 Date last modified:	2012-10-01
 *******************************************************
 Modification History
 *******************************************************
 2012-10-01		Initial version.
 ******************************************************/
package pcsync.server.ctrl;

import org.apache.log4j.Logger;

import pcsync.server.Server;

/**
 * @author Jean-Philippe
 *
 */
public class Controller
{
	@SuppressWarnings("unused")
	private Logger logger;
	private Server server;
	private Thread serverThread;
	
	public Controller()
	{
		logger = Logger.getLogger(this.getClass().getCanonicalName());
		server = new Server();
	}
	
	public boolean startServer()
	{
		if( server == null ) {
			server = new Server();
		}
		
		if( serverThread == null ) {
			serverThread = new Thread(server);
			serverThread.setName("server");
			serverThread.start();
		}
		else
		{
			return false;
		}
		
		return true;
	}
	
	public boolean stopServer()
	{
		server.stop();
		serverThread.interrupt();
		return true;
	}
	
	public int getServerState()
	{
		return server.getState();
	}
}
